﻿using EntityClassMaker.Mods;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace EntityClassMaker.Comman
{
    public class LoginComd: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private LoginMod loginmod;
        /// <summary>
        /// 前端文本框绑定值
        /// </summary>
        public LoginMod loginMod
        {
            get
            {
                if (loginmod == null) loginmod = new LoginMod();
                return loginmod;
            }
            set
            {
                if (loginmod == null) loginmod = new LoginMod();
                loginmod = value;
                NotifyPropertyChanged("loginMod");
            }
        }

        public ICommand LoginCamd
        {
            get
            {
                return new DelegateCommand<object>((obj) =>
                {
                    if (!loginMod.LoginTextCorrect)
                    {
                        new MainWindow().Show();
                        (obj as Window).Close();
                    } 
                }
                );
            }
        }

        public ICommand CheckBoxCamd
        {
            get
            {
                return new DelegateCommand<object>((obj) =>
                {
                    bool isclick = (bool)(obj as CheckBox).IsChecked;
                    if (isclick)
                    {
                        Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog();
                        //dialog.Filter = "文本文件|*.txt";
                        if (dialog.ShowDialog() == true)
                        {
                            var path = dialog.FileName;
                        }
                    }
                }
                );
            }
        }


        #region[    退出事件    ]
        /// <summary>
        /// 退出当前程序
        /// </summary>
        public ICommand ExiteCmd
        {
            get
            {
                return new DelegateCommand<object>((obj) =>
                {
                    Environment.Exit(0);
                });
            }
        }
        #endregion
    }
}
